package com.raymond.http;


import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.util.concurrent.DefaultPromise;
import lombok.Data;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * 消息管理器
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-07-19 11:39
 */
@Data
public class MessageManages {

    private DefaultPromise<FullHttpResponse> promise;

    private String url;

    public MessageManages(DefaultPromise<FullHttpResponse> promise, String url) {
        this.promise = promise;
        this.url = url;
    }

    protected FullHttpResponse get() {
        try {
            return promise.get();
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException("获取响应异常：", e);
        }
    }

    protected FullHttpResponse get(long timeout, TimeUnit unit) {
        try {
            return promise.get(timeout, unit);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            throw new RuntimeException("获取响应异常：", e);
        }
    }

}
